public class ClientHandler implements Runnable {
    private Socket controlSocket;
    private BufferedReader in;
    private PrintWriter out;
    private boolean authenticated = false;

    public ClientHandler(Socket socket) {
        this.controlSocket = socket;
    }

    @Override
    public void run() {
        try {
            in = new BufferedReader(new InputStreamReader(controlSocket.getInputStream()));
            out = new PrintWriter(controlSocket.getOutputStream(), true);

            out.println("220 FTP Server Ready");

            String inputLine;
            while ((inputLine = in.readLine()) != null) {
                String[] tokens = inputLine.split(" ");
                String command = tokens[0].toUpperCase();

                switch (command) {
                    case "USER":
                        handleUser(tokens);
                        break;
                    case "PASS":
                        handlePass(tokens);
                        break;
                    case "LIST":
                        handleList();
                        break;
                    case "RETR":
                        handleRetr(tokens);
                        break;
                    case "STOR":
                        handleStor(tokens);
                        break;
                    case "QUIT":
                        handleQuit();
                        return;
                    default:
                        out.println("500 Unknown command");
                }
            }
        } catch (IOException e) {
            System.err.println("Client handler error: " + e.getMessage());
        } finally {
            try {
                controlSocket.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    private void handleUser(String[] tokens) {
        if (tokens.length < 2) {
            out.println("501 Syntax error in parameters or arguments");
            return;
        }
        // 简单验证用户名
        out.println("331 User name okay, need password");
    }

    private void handlePass(String[] tokens) {
        if (tokens.length < 2) {
            out.println("501 Syntax error in parameters or arguments");
            return;
        }
        // 简单验证密码
        authenticated = true;
        out.println("230 User logged in successfully");
    }

    // 其他命令处理方法...
}